/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package smary.ejb.entity;

import java.io.Serializable;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Abbildung der Scrum üblichen Rollen in einer Tabelle. Die User sind per
 * 1 zu N Beziehung zugeordnet.
 * @author Alex
 *
 * 
 */
@Entity
@Table(name = "ROLLEN")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Rollen.findAll", query = "SELECT r FROM Rollen r"),
    @NamedQuery(name = "Rollen.findByRollenid", query = "SELECT r FROM Rollen r WHERE r.rollenid = :rollenid"),
    @NamedQuery(name = "Rollen.findByRollenname", query = "SELECT r FROM Rollen r WHERE r.rollenname = :rollenname")})
public class Rollen implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "ROLLENID")
    @GeneratedValue(strategy= GenerationType.AUTO)
    private Short rollenid;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 150)
    @Column(name = "ROLLENNAME")
    private String rollenname;

    @OneToMany(mappedBy="rolle")
    protected Set<Userloginaccount> userloginaccounts;

    public Set<Userloginaccount> getUserloginaccounts() {
        return userloginaccounts;
    }

    public void setUserloginaccounts(Set<Userloginaccount> userloginaccounts) {
        this.userloginaccounts = userloginaccounts;
    }
    
    public Rollen() {
    }

    public Rollen(Short rollenid) {
        this.rollenid = rollenid;
    }

    public Rollen(Short rollenid, String rollenname) {
        this.rollenid = rollenid;
        this.rollenname = rollenname;
    }

    public Short getRollenid() {
        return rollenid;
    }

    public void setRollenid(Short rollenid) {
        this.rollenid = rollenid;
    }

    public String getRollenname() {
        return rollenname;
    }

    public void setRollenname(String rollenname) {
        this.rollenname = rollenname;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (rollenid != null ? rollenid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Rollen)) {
            return false;
        }
        Rollen other = (Rollen) object;
        if ((this.rollenid == null && other.rollenid != null) || (this.rollenid != null && !this.rollenid.equals(other.rollenid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getRollenname();
    }    
}
